import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

const API = {
  // 告警列表分页
  page: '/equipment-alarm/page',
  // 告警列表
  list: '/equipment-alarm/list',
  // 告警删除
  delete: '/equipment-alarm/delete',
  // 告警详情
  info: '/equipment-alarm/info',
  // 派单
  assign: '/equipment-alarm/assign',
  // 新增告警数
  add: '/equipment-alarm/add',
  // 修改告警信息
  modify: '/equipment-alarm/modify',
  // 今日报警总数
  count: '/equipment-alarm/count',
  // 区域告警
  summaryRegion: '/equipment-alarm/summary-region',
}

/**
 * 获取告警分页列表
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/pageUsingGET}
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const alarmPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
}

/**
 * 根据ID获取告警详情
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/infoUsingGET}
 * @returns
 */
export const alarmInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 区域告警
 * 文档地址 {@link http://192.168.1.55:38080/api/#/default/%E8%AE%BE%E5%A4%87%E5%91%8A%E8%AD%A6/summaryByRegionUsingPOST}
 * @returns
 */
export const alarmSummaryRegionApi = async (data) => {
  return await defHttp.post({ url: API.summaryRegion, data });
}

/**
 * 获取告警列表
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/listUsingGET}
 * @returns
 */
export const alarmListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}


/**
 * 获取告警列表
 * 文档地址 {@link http://192.168.1.55:38080/api/#/default/%E8%AE%BE%E5%A4%87%E5%91%8A%E8%AD%A6/todayCountUsingPOST}
 * @returns
 */
export const alarmCountApi = async (data) => {
  return await defHttp.post({ url: API.count, data });
}

/**
 * 新增告警数据
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/addUsingPOST}
 * @param {String} assignTo 处理人
 * @param {String} attachments 附件
 * @param {String} createBy 创建人
 * @param {String} handleTime 处理时间
 * @param {String} latestHandleTime 截至时间
 * @param {String} orderNum 工单编号
 * @param {String} remark 备注
 * @param {String} status 状态
 * @param {String} tel 联系电话
 * @returns
 */
export const alarmAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.add, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 告警编辑
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/modifyUsingPOST}
 * @param {String} assignTo 处理人
 * @param {String} attachments 附件
 * @param {String} createBy 创建人
 * @param {String} handleTime 处理时间
 * @param {String} latestHandleTime 截至时间
 * @param {String} orderNum 工单编号
 * @param {String} remark 备注
 * @param {String} status 状态
 * @param {String} tel 联系电话
 * @returns
 */
export const alarmModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除告警接口
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/deleteUsingPOST}
 * @param {*} id 告警ID
 * @returns
 */
export const alarmDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前告警数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}

/**
 * 派单请求
 * 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E5%91%8A%E8%AD%A6/modifyUsingPOST_1}
 * @param {String} assignTo 处理人
 * @param {String} attachments 附件
 * @param {String} createBy 创建人
 * @param {String} handleTime 处理时间
 * @param {String} latestHandleTime 截至时间
 * @param {String} orderNum 工单编号
 * @param {String} remark 备注
 * @param {String} status 状态
 * @param {String} tel 联系电话
 * @returns
 */
export const alarmAssignApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交指派工单数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.assign, data }).then((res) => {
          message.success('指派工单成功');
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}